import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//import './api/mock'
import Cookie from 'js-cookie'

Vue.config.productionTip = false
Vue.use(ElementUI);

import axios from 'axios'
import VueAxios from 'vue-axios'

axios.defaults.withCredentials = true
Vue.use(VueAxios, axios);

axios.defaults.baseURL = 'http://8.130.52.6:8091'
    // axios.defaults.baseURL = 'http://8.130.95.155:8070/'
axios.interceptors.request.use(config => {
    config.headers.token = Cookie.get("token")
    return config
})

axios.interceptors.response.use(response => {
    if (response.data.redirectUrl != null) {
        window.location.href = response.data.redirectUrl;
    }
    return response
})

router.beforeEach((to, from, next) => {
    let geturl = window.location.href
    let getqyinfo = geturl.split('?')[1]
    let getqys = new URLSearchParams('?' + getqyinfo)
    let getqycode = getqys.get('DSESSION')
    if (getqycode) {
        Cookie.set("DSESSION", getqycode)
    }
    const token = Cookie.get('token')
    next();
})

new Vue({
    router,
    store,
    render: h => h(App),
    created() {
        store.commit('addMenu', router)
    }
}).$mount('#app')